package z.nat;

import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;

import java.util.Arrays;

public class MyService extends Service {

    public static boolean running;

    @Override
    public void onCreate() {
        super.onCreate();
        new Thread(() -> {
            try {
                running = true;
                WebSocketClient.main(new String[]{});
            } catch (Exception e) {
                MainActivity.toast(Arrays.toString(e.getStackTrace()));
            }
        }).start();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        WebSocketClient.stop();
        running = false;
        stopForeground(true);
    }
}